package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsTrack;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsTrackDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2021-07-05 11:06:23
 */
public class LbsTrackConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsTrackConverts.class);

    public static List<LbsTrackDTO> convert(List<LbsTrack> lbsTrackList) {
        if (CollectionUtils.isEmpty(lbsTrackList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsTrackDTO> lbsTrackListResult = Lists.newArrayList();
        for (LbsTrack lbsTrack : lbsTrackList) {
            lbsTrackListResult.add(convert(lbsTrack));
        }
        return lbsTrackListResult;
    }

    public static LbsTrackDTO convert(LbsTrack lbsTrack) {
        try {
            return BeanUtils.copy(lbsTrack, LbsTrackDTO.class);
        } catch (Exception e) {
            LOG.error("LbsTrack到LbsTrackDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTrack到LbsTrackDTO转换失败", e);
        }
    }

    public static LbsTrack convert(LbsTrackDTO lbsTrackDTO) {
        try {
            return BeanUtils.copy(lbsTrackDTO, LbsTrack.class);
        } catch (Exception e) {
            LOG.error("LbsTrackDTO到LbsTrack转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTrackDTO到LbsTrack转换失败", e);
        }
    }
}